package com.woniu.day8.service.Impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.woniu.day8.mapper.ParkingMapper;
import com.woniu.day8.pojo.Parking;
import com.woniu.day8.pojo.UserInfo;
import com.woniu.day8.service.ParkingService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class ParkingServiceImpl extends ServiceImpl<ParkingMapper, Parking> implements ParkingService {
    @Autowired
    private ParkingMapper parkingMapper;
    @Override
    public List< Parking> queryParking(Page<UserInfo> page, Parking conditions){
        QueryWrapper<UserInfo> queryWrapper = new QueryWrapper<>();

        // 添加查询条件
        if (conditions.getId() != null) {
            queryWrapper.eq("id", conditions.getId());// id查询
        }
        if (conditions.getNumbers() != null && !conditions.getNumbers().isEmpty()) {
            queryWrapper.like("numbers", conditions.getNumbers());//车位号查询（原代码错误地使用了username）
        }
        if (conditions.getStatus() != null) {
            queryWrapper.eq("status", conditions.getStatus());//状态查询（原代码错误地使用了type）
        }
        // 使用自定义的queryUsers方法查询用户及其角色信息
        List<Parking> list = parkingMapper.selectParking(page, queryWrapper);
        return list;
    }
}
